#include <xscript/xabstractsyntaxtree.h>
#include <xscript/xprint.h>
#include <astree/xabstractsyntaxtreeparser.h>
#include <astree/xabstractasyntaxtreevariable.h>

XAbstractSyntaxTreePtr XAbstractSyntaxTreeParserVariable::parse(const std::vector<XTokenPtr>& tokens) {
    if (tokens.size() != 1) {
        XScriptExecutor::getInstance()->setError(XError::XError_Unsupported, tokens.at(0)->toString());
        return nullptr;
    }

    auto token = tokens.at(0);
    if (!token->asVariable()) {
        XScriptExecutor::getInstance()->setError(XError::XError_BadTokenError, tokens.at(0)->toString());
        return nullptr;
    }
    return std::make_shared<XAbstractSyntaxTreeVariable>(token);
}
